﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business_Objects;
using ServicesComponent.Repositories;

public partial class QuanLyHocSinh_PhanLop : System.Web.UI.Page
{
    public int id = 1;
    private IPhanLopRepository _PhanLopRepository;
    private IClassRepository _ClassRepository;
    protected void Page_Load(object sender, EventArgs e)
    {
        id = id + 1;
        if (!IsPostBack)
        {
            if (Request.QueryString["Refresh"] != null)
            {
                _PhanLopRepository = FactoryServices.GetServicesPhanLop(_PhanLopRepository);
                Bind();
                return;
            }
            if (Request.QueryString["Page"] != null)
            {
                id = (int.Parse(Request.QueryString["Page"].ToString()) - 1) * 14 + 1;
            }
        }
        _PhanLopRepository = FactoryServices.GetServicesPhanLop(_PhanLopRepository);
        _ClassRepository = FactoryServices.GetServicesClass(_ClassRepository);
        Bind();
    }
    //Delete Recall 
    void Bind()
    {
        rptA.Dispose();
        // rptA.RenderControl("f");
        rptA.DataSource = null;
        //   rptA.BeginResetItemTemplate();
        //Truyền @ClassID="";
       rptA.DataSource = _PhanLopRepository.GetPhanLopBySchoolIdAndSchoolYearIDAndClassID(Session["SchoolYearID"].ToString(),int.Parse(Session["SchoolID"].ToString()),"");
       // rptA.DataSource = _ClassRepository.GetClassPhanLopBySchoolIdAndSchoolYearID(Session["SchoolYearID"].ToString(), int.Parse(Session["SchoolID"].ToString()));
        rptA.DataBind();
        Cpage.DataSource = _PhanLopRepository.GetPhanLopBySchoolIdAndSchoolYearIDAndClassID(Session["SchoolYearID"].ToString(), int.Parse(Session["SchoolID"].ToString()),"");
        // Cpage.DataSource = _ClassRepository.GetClassPhanLopBySchoolIdAndSchoolYearID(Session["SchoolYearID"].ToString(), int.Parse(Session["SchoolID"].ToString()));
        Cpage.BindToControl = rptA;
        rptA.DataSource = Cpage.DataSourcePaged;
        // drAddress.EndResetItemTemplate()

    }

    public string GetTenLopById(string id)
    {
        Class obj = _ClassRepository.Get(id);
        return obj.Name;
    }
    public string ConVertDate(DateTime startDate)
    {
        return startDate.ToShortDateString();
    }
}